import { Exception } from "../../../../../Core/Object/Exception";
import { ETTask } from "../../../../../Support/Share/Lib/Async/ETTask";

export class HttpClientHelper {

    public static async Get(link: string): Promise<string> {
        try {
            const tcs = ETTask.Create<string>();
            const xhr = new XMLHttpRequest();
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    const response = xhr.responseText;

                    // 处理响应数据
                    // console.log(`XMLHttpRequest.Response:${response}`);
                    tcs.SetResult("Result");
                }
            };
            xhr.open("POST", link, true);
            xhr.send();
            return tcs;
        } catch (e) {
            throw new Exception(`http request fail: ${link.substring(0, link.indexOf('?'))}\n${e}`);
        }
    }

}